//
//  YYENavigationController.swift
//  weibo14
//
//  Created by mac on 16/3/2.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class YYENavigationController: UINavigationController {

    override func viewDidLoad() {
        
        super.viewDidLoad()

        
    }


    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        if childViewControllers.count > 0 {
        
            var title = "返回回"
            
            // 代表当前已经存在一个控r制器.正要往里push的第二个控制器,所以获取第一个控制器的title
            if childViewControllers.count == 1 {
            
                title = childViewControllers.first?.title ?? "返回回"
            }
        
            // 添加自己的逻辑
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imageNamed: "navigationbar_back_withtext", title: title, target: self, action: "back")
            
            viewController.hidesBottomBarWhenPushed = true
            
        }
        super.pushViewController(viewController, animated: animated)
    }

    @objc private func back(){
        popViewControllerAnimated(true)
    }
    
}
